package com.yunwaikeji.gy_tool_library.widget.recycler.image;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import com.yunwaikeji.gy_tool_library.info.GYImageRecyclerInfo;
import com.yunwaikeji.gy_tool_library.utils.display.GYDisplayUtils;

public class GYImageRecyclerBuilder implements GYImageRecyclerInfo {
    private final Context context;
    private final GYImageRecyclerView imageRecyclerView;
    private String itemProportion;
    private int itemRadiusLeftTopPx = 0;
    private int itemRadiusRightTopPx = 0;
    private int itemRadiusRightBottomPx = 0;
    private int itemRadiusLeftBottomPx = 0;
    private int itemWidthPx = WRAP_CONTENT;
    private int itemHeightPx = WRAP_CONTENT;
    private boolean edit;
    private Drawable addDrawable;
    private float addDrawableWidth = MATCH_PARENT;
    private float addDrawableHeight = MATCH_PARENT;
    private int deleteLocation = DeleteLocation.RIGHT_TOP;
    private Drawable deleteDrawable;
    private int deleteDrawableWidthPx;
    private int deleteDrawableHeightPx;
    private int deleteDrawableMarginLeftPx = 0;
    private int deleteDrawableMarginTopPx = 0;
    private int deleteDrawableMarginRightPx = 0;
    private int deleteDrawableMarginBottomPx = 0;
    private int maxImageNumber = WRAP_CONTENT;
    private float imageEdgeWidth = 0;
    private int imageEdgeColor = Color.LTGRAY;
    private boolean imageEdgeOver;
    private float addEdgeWidth = 0;
    private int addEdgeColor = Color.LTGRAY;
    private boolean addEdgeOver;
    private boolean progressShow = true;//是否显示进度
    private float progressTextSize;//进度字体大小
    private float progressTextColor = Color.WHITE;//进度颜色
    private ImageView.ScaleType scaleType = ImageView.ScaleType.CENTER_CROP;
    private Drawable startDrawable;//加载前图片
    private Drawable loadingDrawable;//加载中图片
    private Drawable errorDrawable;//加载失败图片
    private String cacheTab = "Zoom";//缓存图片便签
    private int addLocation = AddLocation.END;//添加按钮位置

    public GYImageRecyclerBuilder(GYImageRecyclerView imageRecyclerView) {
        this.context = imageRecyclerView.getContext();
        this.imageRecyclerView = imageRecyclerView;
        deleteDrawableWidthPx = GYDisplayUtils.dp2px(context, 13);
        deleteDrawableHeightPx = GYDisplayUtils.dp2px(context, 13);
        progressTextSize = GYDisplayUtils.dp2px(context, 17);
    }

    public GYImageRecyclerView build() {
        imageRecyclerView.addModel();
        imageRecyclerView.notifyDataSetChanged();
        return imageRecyclerView;
    }

    public Context getContext() {
        return context;
    }

    public GYImageRecyclerView getImageRecyclerView() {
        return imageRecyclerView;
    }

    public String getItemProportion() {
        return itemProportion;
    }

    public GYImageRecyclerBuilder setItemProportion(String itemProportion) {
        this.itemProportion = itemProportion;
        return this;
    }

    public int getItemRadiusLeftTopPx() {
        return itemRadiusLeftTopPx;
    }

    public GYImageRecyclerBuilder setItemRadiusLeftTopPx(int itemRadiusLeftTopPx) {
        this.itemRadiusLeftTopPx = itemRadiusLeftTopPx;
        return this;
    }

    public int getItemRadiusRightTopPx() {
        return itemRadiusRightTopPx;
    }

    public GYImageRecyclerBuilder setItemRadiusRightTopPx(int itemRadiusRightTopPx) {
        this.itemRadiusRightTopPx = itemRadiusRightTopPx;
        return this;
    }

    public int getItemRadiusRightBottomPx() {
        return itemRadiusRightBottomPx;
    }

    public GYImageRecyclerBuilder setItemRadiusRightBottomPx(int itemRadiusRightBottomPx) {
        this.itemRadiusRightBottomPx = itemRadiusRightBottomPx;
        return this;
    }

    public int getItemRadiusLeftBottomPx() {
        return itemRadiusLeftBottomPx;
    }

    public GYImageRecyclerBuilder setItemRadiusLeftBottomPx(int itemRadiusLeftBottomPx) {
        this.itemRadiusLeftBottomPx = itemRadiusLeftBottomPx;
        return this;
    }

    public int getItemWidthPx() {
        return itemWidthPx;
    }

    public GYImageRecyclerBuilder setItemWidthPx(int itemWidthPx) {
        this.itemWidthPx = itemWidthPx;
        return this;
    }

    public int getItemHeightPx() {
        return itemHeightPx;
    }

    public GYImageRecyclerBuilder setItemHeightPx(int itemHeightPx) {
        this.itemHeightPx = itemHeightPx;
        return this;
    }

    public boolean isEdit() {
        return edit;
    }

    public GYImageRecyclerBuilder setEdit(boolean edit) {
        this.edit = edit;
        for (GYImageRecyclerModel imageModel : imageRecyclerView.getImageAdapter().getData()) {
            imageModel.setEdit(null);
        }
        return this;
    }

    public Drawable getAddDrawable() {
        return addDrawable;
    }

    public GYImageRecyclerBuilder setAddDrawable(Drawable addDrawable) {
        this.addDrawable = addDrawable;
        return this;
    }

    public float getAddDrawableWidth() {
        return addDrawableWidth;
    }

    public GYImageRecyclerBuilder setAddDrawableWidth(float addDrawableWidth) {
        this.addDrawableWidth = addDrawableWidth;
        return this;
    }

    public float getAddDrawableHeight() {
        return addDrawableHeight;
    }

    public GYImageRecyclerBuilder setAddDrawableHeight(float addDrawableHeight) {
        this.addDrawableHeight = addDrawableHeight;
        return this;
    }

    public int getDeleteLocation() {
        return deleteLocation;
    }

    public GYImageRecyclerBuilder setDeleteLocation(int deleteLocation) {
        this.deleteLocation = deleteLocation;
        return this;
    }

    public Drawable getDeleteDrawable() {
        return deleteDrawable;
    }

    public GYImageRecyclerBuilder setDeleteDrawable(Drawable deleteDrawable) {
        this.deleteDrawable = deleteDrawable;
        return this;
    }

    public int getDeleteDrawableWidthPx() {
        return deleteDrawableWidthPx;
    }

    public GYImageRecyclerBuilder setDeleteDrawableWidthPx(int deleteDrawableWidthPx) {
        this.deleteDrawableWidthPx = deleteDrawableWidthPx;
        return this;
    }

    public int getDeleteDrawableHeightPx() {
        return deleteDrawableHeightPx;
    }

    public GYImageRecyclerBuilder setDeleteDrawableHeightPx(int deleteDrawableHeightPx) {
        this.deleteDrawableHeightPx = deleteDrawableHeightPx;
        return this;
    }

    public int getDeleteDrawableMarginLeftPx() {
        return deleteDrawableMarginLeftPx;
    }

    public GYImageRecyclerBuilder setDeleteDrawableMarginLeftPx(int deleteDrawableMarginLeftPx) {
        this.deleteDrawableMarginLeftPx = deleteDrawableMarginLeftPx;
        return this;
    }

    public int getDeleteDrawableMarginTopPx() {
        return deleteDrawableMarginTopPx;
    }

    public GYImageRecyclerBuilder setDeleteDrawableMarginTopPx(int deleteDrawableMarginTopPx) {
        this.deleteDrawableMarginTopPx = deleteDrawableMarginTopPx;
        return this;
    }

    public int getDeleteDrawableMarginRightPx() {
        return deleteDrawableMarginRightPx;
    }

    public GYImageRecyclerBuilder setDeleteDrawableMarginRightPx(
            int deleteDrawableMarginRightPx) {
        this.deleteDrawableMarginRightPx = deleteDrawableMarginRightPx;
        return this;
    }

    public int getDeleteDrawableMarginBottomPx() {
        return deleteDrawableMarginBottomPx;
    }

    public GYImageRecyclerBuilder setDeleteDrawableMarginBottomPx(
            int deleteDrawableMarginBottomPx) {
        this.deleteDrawableMarginBottomPx = deleteDrawableMarginBottomPx;
        return this;
    }

    public int getMaxImageNumber() {
        return maxImageNumber;
    }

    public GYImageRecyclerBuilder setMaxImageNumber(int maxImageNumber) {
        this.maxImageNumber = maxImageNumber;
        return this;
    }

    public float getImageEdgeWidth() {
        return imageEdgeWidth;
    }

    public GYImageRecyclerBuilder setImageEdgeWidth(float imageEdgeWidth) {
        this.imageEdgeWidth = imageEdgeWidth;
        return this;
    }

    public int getImageEdgeColor() {
        return imageEdgeColor;
    }

    public GYImageRecyclerBuilder setImageEdgeColor(int imageEdgeColor) {
        this.imageEdgeColor = imageEdgeColor;
        return this;
    }

    public boolean isImageEdgeOver() {
        return imageEdgeOver;
    }

    public GYImageRecyclerBuilder setImageEdgeOver(boolean imageEdgeOver) {
        this.imageEdgeOver = imageEdgeOver;
        return this;
    }

    public float getAddEdgeWidth() {
        return addEdgeWidth;
    }

    public GYImageRecyclerBuilder setAddEdgeWidth(float addEdgeWidth) {
        this.addEdgeWidth = addEdgeWidth;
        return this;
    }

    public int getAddEdgeColor() {
        return addEdgeColor;
    }

    public GYImageRecyclerBuilder setAddEdgeColor(int addEdgeColor) {
        this.addEdgeColor = addEdgeColor;
        return this;
    }

    public boolean isAddEdgeOver() {
        return addEdgeOver;
    }

    public GYImageRecyclerBuilder setAddEdgeOver(boolean addEdgeOver) {
        this.addEdgeOver = addEdgeOver;
        return this;
    }

    public boolean isProgressShow() {
        return progressShow;
    }

    public GYImageRecyclerBuilder setProgressShow(boolean progressShow) {
        this.progressShow = progressShow;
        return this;
    }

    public float getProgressTextSize() {
        return progressTextSize;
    }

    public GYImageRecyclerBuilder setProgressTextSize(float progressTextSize) {
        this.progressTextSize = progressTextSize;
        return this;
    }

    public float getProgressTextColor() {
        return progressTextColor;
    }

    public GYImageRecyclerBuilder setProgressTextColor(float progressTextColor) {
        this.progressTextColor = progressTextColor;
        return this;
    }

    public ImageView.ScaleType getScaleType() {
        return scaleType;
    }

    public GYImageRecyclerBuilder setScaleType(ImageView.ScaleType scaleType) {
        this.scaleType = scaleType;
        return this;
    }

    public Drawable getStartDrawable() {
        return startDrawable;
    }

    public GYImageRecyclerBuilder setStartDrawable(Drawable startDrawable) {
        this.startDrawable = startDrawable;
        return this;
    }

    public Drawable getLoadingDrawable() {
        return loadingDrawable;
    }

    public GYImageRecyclerBuilder setLoadingDrawable(Drawable loadingDrawable) {
        this.loadingDrawable = loadingDrawable;
        return this;
    }

    public Drawable getErrorDrawable() {
        return errorDrawable;
    }

    public GYImageRecyclerBuilder setErrorDrawable(Drawable errorDrawable) {
        this.errorDrawable = errorDrawable;
        return this;
    }

    public String getCacheTab() {
        return cacheTab;
    }

    public GYImageRecyclerBuilder setCacheTab(String cacheTab) {
        this.cacheTab = cacheTab;
        return this;
    }

    public GYImageRecyclerBuilder setAddLocation(@AddLocation int addLocation) {
        this.addLocation = addLocation;
        return this;
    }

    @AddLocation
    public int getAddLocation() {
        return addLocation;
    }
}
